<template>
	<el-container>
		<el-container>
			<el-header>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.end_price" placeholder="选择年月日" clearable></el-input>
						<el-select v-model="search.pay_type" filterable placeholder="请选择审核状态">
							<el-option label="是" :value="1"/>
							<el-option label="否" :value="2"/>
						</el-select>
						<el-select v-model="search.pay_type" filterable placeholder="请选择单据来源">
							<el-option label="是" :value="1"/>
							<el-option label="否" :value="2"/>
						</el-select>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
						<el-button type="info" @click="refresh">重置</el-button>
					</div>
				</div>
				<div class="left-panel">
					<el-button type="primary" @click="add" v-auth="'storage.add'">新增</el-button>
					<el-button type="primary" @click="batch_show" :disabled="selection.length !== 1" v-auth="'storage.show'">查看</el-button>
					<el-button type="primary" :disabled="selection.length !== 1" @click="batch_edit" v-auth="'storage.edit'">修改</el-button>
					<el-button type="danger" :disabled="selection.length == 0" @click="batch_del" v-auth="'storage.delete'">删除</el-button>
					<el-button type="danger" :disabled="selection.length == 0" @click="add" v-auth="'storage.return'">退库</el-button>
					<el-button type="success" :disabled="selection.length != 1" @click="checkExamine" v-auth="'storage.audit'">审核</el-button>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable @row-dblclick="dblclick" ref="table" :apiObj="apiObj" row-key="id"  @selection-change="selectionChange" stripe remoteSort remoteFilter border>
					<el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
					<el-table-column label="序号" type="index" align="center" width="50"></el-table-column>
					<el-table-column label="单据日期" prop="product_date" align="center"></el-table-column>
					<el-table-column label="单据编号" prop="product_code" align="center"></el-table-column>
					<!-- <el-table-column label="单据标签" prop="customAddress" align="center"></el-table-column> -->
					<el-table-column label="交货部门" prop="delivery_depart" align="center"></el-table-column>
					<el-table-column label="审核状态" prop="status" align="center">
                        <template #default="{row}">
                            <el-tag :type="row.status == 0 ? 'warning' : row.status == 1 ? 'success' : 'danger'">{{row.status == 0 ? '待审核' : row.status == 1 ? '审核通过' : '审核驳回'}}</el-tag>
                        </template>
                    </el-table-column>
					<!-- <el-table-column label="商品编码" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="仓库名称" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="单位" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="计划入库数" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="已入库数" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="本次入库数" prop="customAddress" align="center"></el-table-column>
					<el-table-column label="单据来源" prop="customAddress" align="center"></el-table-column> -->
                    <el-table-column label="操作" align="center" width="220">
                        <template #default="scope">
                            <el-button-group>
                                <el-button text type="primary" size="small" @click="goDetail(scope.row, scope.$index)">查看入库记录</el-button>
                            </el-button-group>
                        </template>
                    </el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
    <check-status v-if="dialog.check" ref="checkDialog" @success="handleSuccess" @closed="dialog.check = false"></check-status>
    <shop-detail v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false"></shop-detail>
</template>

<script>
import CheckStatus from './checkStatus.vue'
import ShopDetail from './shopDetail.vue'
export default {
	name: 'user',
	components: {
        CheckStatus,ShopDetail
	},
	data() {
	    return {
			dialog: {
				check: false,
			},
			group: [],
			apiObj: this.$API.production.inhouse.list,
			selection: [],
			search: {
				title: null,
				cid: null,
			},
		}
	},
	watch: {

	},
	mounted() {

	},
	methods: {
		//添加
		add() {
			this.$router.push({
				path: '/production/storage/addStorage'
			});
		},
		//编辑
		batch_edit() {
			let form = this.selection[0]
			form.zhuangtai = 'edit'
			this.$router.push({
				path: '/production/storage/addStorage',
				query: form
			});
		},
		//查看
		table_show(row) {
			let form = row
			form.zhuangtai = 'show'
			this.$router.push({
				path: '/production/storage/addStorage',
				query: form
			});
		},
        goDetail(row){
            this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
        },
		/**双击事件*/
		dblclick(row) {
			this.table_show(row)
		},
		//删除
		async table_del(row, index) {
			var reqData = {id: row.id}
			var res = await this.$API.production.inhouse.delete.post(reqData);
			if (res.code == 1) {
				this.$refs.table.tableData.splice(index, 1);
				this.$refs.table.refresh();
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
        //批量删除
		async batch_del() {
			var delete_ids = [];
			this.selection.forEach((item) => {
				delete_ids.push(item.id)
			})
			this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
				type: 'warning'
			}).then(() => {
				this.table_del_all(delete_ids)
			}).catch(() => {

			})
		},
        async table_del_all(delete_ids) {
			var reqData = {id: delete_ids}
			var res = await this.$API.production.inhouse.delete.post(reqData);
			if (res.code == 1) {
				this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		},
		selectionChange(selection) {
			this.selection = selection;
		},
        checkExamine(){
            this.dialog.check = true
			this.$nextTick(() => {
				this.$refs.checkDialog.open('edit').setData(this.selection[0].id)
			})
        },
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}

.shopInfo {
	display: flex;
	align-items: center;
}

.img {
	width: 100px;
	height: 100px;
	margin-right: 5px;
}
</style>
